package aryn.mapEditor;

import java.awt.Graphics;

import aryn.framework.display.MyPanel;

public class Board extends MyPanel {
	private static final long serialVersionUID = 1L;
		
	private boolean grid;
	
	public Board(String name, int x, int y, int width, int height) {
		super(name, x, y, width, height);
		addMouseListener();
		addMouseMotionListener();
		Loader loader = Loader.getInstance();
		addImage(loader.getBoardImg(), 0, 0);
		grid = true;
	}
	
	protected void postRender(Graphics g) {
		mouse.drawSelection(this, g);
		if (grid) drawGrid(g);
		int minX = mouse.getSelectionMinX();
		int minY = mouse.getSelectionMinY();
		int maxX = mouse.getSelectionMaxX();
		int maxY = mouse.getSelectionMaxY();
		// determinare quali quadrati sono selezionati e disegnarli col botdo rosso.
		// creare un array delle dimensioni opportune da contenere i singoli tile della board.
		// mettere i tiles nel menu a sinistra.
		// deselect col mouse 3 e quando clicki il singolo, fai bordo rosso
	}
	
	private void drawGrid(Graphics g) {
		int tileDim = Config.getTileDim();
		for(int i = 0; i < this.getWidth() / tileDim; i++)
			g.drawLine(i*tileDim, 0, i*tileDim, Config.getScreenHeight());
		for(int j = 0; j < this.getHeight() / tileDim + 1; j++)
			g.drawLine(0, j*tileDim, Config.getScreenWidth(), j*tileDim);
	}
}
